<?php
// 搜索参数
$_GET['pid']	= empty($_GET['pid']) ? 0 : $_GET['pid'];
$_GET['depth'] = empty($_GET['depth']) ? 0 : 1;

$list = null;
if(empty($_GET['pid']) && empty($_GET['depth'])){
	$news_categorys = cache_read('news_categorys.php');
	$list = $news_categorys['category_list'];
}
if(empty($list)){
	$oNewscat = new Newscat();
	$list = $oNewscat->get_category_list($_GET['pid'], true, 0, $_GET['depth']);
}

if(!empty($list)){

	if(!empty($_GET['btnExport'])){	// 导出
		$data = array();
		foreach($list as $key => $row){
			$row['name'] = str_repeat('　　', $row['level']).$row['name'];
			$row['time'] = utime($row['addtime'], $row['updatetime']);
			$data[] = $row;
		}

		$headers = array(
			'id'		=> array('title' => 'ID',		'width' => '6'),
			'name'		=> array('title' => '名称', 	'width' => '50'),
			'mark'		=> array('title' => '标识', 	'width' => '12.5'),
			'memo'		=> array('title' => '备注', 	'width' => '50', 'wrap' => true),
			'time'		=> array('title' => '时间', 	'width' => '18'),
		);
		$oExcel = new Excel();
		$oExcel->export($headers, $data, '_E_新闻分类_'.date('Ymd_His').'.xlsx');
		exit;
	}

	foreach($list as $key => $row){
		$row['name'] = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $row['level']).$row['name'];
		if($row['hsub'] == 1){
			$row['hsub'] = $__l['is'];
		}else{
			$row['hsub'] = '--';
		}
		$row['addtime'] = ftime($row['addtime']);
		$row['updatetime'] = ftime($row['updatetime']);
		$list['list'][$key] = $row;
	}
	$vars['list'] = $list['list'];
	$vars['total'] = count($list);
}
?>